package jkim.plugin.daframe.ext.sql.views.actions;

import jkim.plugin.daframe.ext.sql.model.DaframeSQLLogInfo;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.swt.widgets.Display;

public class DaframeSQLLoggerCopyLogAction extends Action {

	private TableViewer viewer;
	public DaframeSQLLoggerCopyLogAction(TableViewer viewer) {
		super();
		this.viewer = viewer;
	}

	public DaframeSQLLoggerCopyLogAction(TableViewer viewer, String text, ImageDescriptor image) {
		super(text, image);
		this.viewer = viewer;
	}

	public DaframeSQLLoggerCopyLogAction(TableViewer viewer, String text, int style) {
		super(text, style);
		this.viewer = viewer;
	}

	public DaframeSQLLoggerCopyLogAction(TableViewer viewer, String text) {
		super(text);
		this.viewer = viewer;
	}

	@Override
	public void run() {
		StructuredSelection obj = (StructuredSelection)viewer.getSelection();
		DaframeSQLLogInfo info = (DaframeSQLLogInfo) obj.getFirstElement();
		new Clipboard(Display.getCurrent()).setContents(new Object[] { info.toStringQuery() }, new Transfer[] { TextTransfer.getInstance() });
	}
}
